package com.wanghlme.exercise05.web;

import com.wanghlme.exercise05.pojo.Emp;
import com.wanghlme.exercise05.service.IEmpService;
import com.wanghlme.exercise05.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/toEdit")
public class ToEditAction extends HttpServlet {
    private IEmpService empService;

    public ToEditAction() {
        empService = new EmpServiceImpl();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        Emp emp = empService.queryOneById(Integer.parseInt(id));
        req.setAttribute("emp", emp);
        this.getServletContext().getRequestDispatcher("/page/add.jsp").forward(req, resp);
    }
}
